package com.emptyMe.org.service.impl;

import com.emptyMe.org.domain.Goods;
import com.emptyMe.org.domain.Shopcart;
import com.emptyMe.org.mapper.ShopCartMapper;
import com.emptyMe.org.query.ShopCartQuery;
import com.emptyMe.org.service.IShopcartService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class ShopCartImpl implements IShopcartService {
    @Resource
    private ShopCartMapper mapper;
    @Transactional
    @Override
    public void SaveShopcart(Shopcart shopcart) {
        if(shopcart.getId()!=null){
            mapper.updateShopcart(shopcart);
        }else{
            mapper.addShopcart(shopcart);
        }
    }

    @Transactional
    @Override
    public void DelShopcart(List<Long> id) {
        mapper.delShopcart(id);
    }

    @Override
    public PageInfo<Shopcart> findAllShopcart(ShopCartQuery query) {
        PageHelper.startPage(query.getCurrentPage(),query.getPageSize());
        List<Shopcart> list = mapper.findAllShopcart(query);
        Page<Shopcart> page = (Page<Shopcart>) list;
        return page.toPageInfo();
    }
}
